export default class barrier1 extends Laya.Script {

    constructor() { super(); }
    private off: Laya.Sprite     //触发开关
    private barrier: Laya.Sprite     //障碍物
    private b_state: boolean

    onEnable(): void {
        //初始化变量
        this.initParams()
    }


    onTriggerEnter(other: Laya.ColliderBase, self: any) {
        if (other.label == "player1"||other.label == "player2") {
            Laya.Tween.to(
                this.off,
                { y: 114 },
                800,
                Laya.Ease.strongInOut,
                Laya.Handler.create(this,()=>{
                    // Laya.timer.once()
                    Laya.Tween.to(
                        this.off,
                        { y: 90 },
                        800,
                        Laya.Ease.strongInOut)
                })
            )
            Laya.Tween.to(
                this.barrier,
                { x: 780 },
                800,
                Laya.Ease.strongInOut,
                Laya.Handler.create(this,()=>{
                    // Laya.timer.once()
                    Laya.Tween.to(
                        this.barrier,
                        { x: 609 },
                        800,
                        Laya.Ease.strongInOut)
                })
            )
        }
        this.b_state = true
    }

    


    initParams() {
        this.off = this.owner.parent.getChildByName("off") as Laya.Sprite
        this.barrier = this.owner.parent.parent.getChildByName("barrier") as Laya.Sprite
    }

    onDisable(): void {

    }
}